<?php //$Rev:: 58         $ // DO NOT REMOVE

function weather_getWeather(&$obj, $data)
{
    if ($text = $obj->core->module->aim_help_requested($data)) {
        echo 'help requested';
        $obj->core->utilities->aim_send_im($data['screenname'], $text, true);
    } else {
        $wx = null;

        $weather = function($icao) use (&$wx) {
            // kill the error so we don't muck up the running of the bot
            $wx = @simplexml_load_file('http://www.weather.gov/xml/current_obs/' . strtoupper($icao) . '.xml');
        };

        $get = function($el) use (&$wx) {
            $el = strtolower($el);
            return ($el == '__all__') ? $wx : $wx->{$el};
        };

        $weather($data['message_text']);
        $message = (!is_object($wx)) ? 'Weather not available for ' . $data['message_text'] : sprintf("Station: %s / Date: %s / Temp: %dF / Weather: %s / Wind: %s",
                                                                                                $get('location'), $get('observation_time_rfc822'),
                                                                                                $get('temp_f'),   $get('weather'), $get('wind_string'));

        if ($data['message_type'] == AIM_MSG_CHAT) {
            $obj->core->chat->aim_chat_send($data['cid'], $message);
        } else {
            $obj->core->utilities->aim_send_im($data['screenname'], $message, true);
        }
    }
}

?>